aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/fund/[id]/withdraw
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-11-10 21:33:49 -0800
committerAdam Soltys <[email protected]>2023-11-11 00:04:22 -0800
commitae87f1d43c6d2cf34bd2ea6fd7b4d28af6d2aa91 (patch)
tree694efda287338a3b81c5d7d41328c9f2e30e5218 /src/routes/(app)/fund/[id]/withdraw
parentefdbc67c17fab67bf3cdce448a30aa82f62c5212 (diff)
downloadcoinos-ui-ae87f1d43c6d2cf34bd2ea6fd7b4d28af6d2aa91.tar.gz
coinos-ui-ae87f1d43c6d2cf34bd2ea6fd7b4d28af6d2aa91.zip
nav update
Diffstat (limited to 'src/routes/(app)/fund/[id]/withdraw')
-rw-r--r--src/routes/(app)/fund/[id]/withdraw/+page.server.js20
-rw-r--r--src/routes/(app)/fund/[id]/withdraw/+page.svelte58
-rw-r--r--src/routes/(app)/fund/[id]/withdraw/+server.js6
3 files changed, 84 insertions, 0 deletions
diff --git a/src/routes/(app)/fund/[id]/withdraw/+page.server.js b/src/routes/(app)/fund/[id]/withdraw/+page.server.js
new file mode 100644
index 00000000..476149f2
--- /dev/null
+++ b/src/routes/(app)/fund/[id]/withdraw/+page.server.js
@@ -0,0 +1,20 @@
+import { fail, json, redirect } from '@sveltejs/kit';
+import { fd, auth, post } from '$lib/utils';
+
+export async function load({ parent }) {
+ let { user } = await parent();
+ if (!user) throw redirect(307, '/register');
+}
+
+export const actions = {
+ default: async ({ cookies, request }) => {
+ let body = await fd(request);
+ try {
+ await post('/take', body, auth(cookies));
+ } catch (e) {
+ return fail(400, { message: e.message });
+ }
+
+ throw redirect(307, `/fund/${body.id}`);
+ }
+};
diff --git a/src/routes/(app)/fund/[id]/withdraw/+page.svelte b/src/routes/(app)/fund/[id]/withdraw/+page.svelte
new file mode 100644
index 00000000..9cad945a
--- /dev/null
+++ b/src/routes/(app)/fund/[id]/withdraw/+page.svelte
@@ -0,0 +1,58 @@
+<script>
+ import { t } from '$lib/translations';
+ import { enhance } from '$app/forms';
+ import { Icon, Numpad, Spinner } from '$comp';
+ import { page } from '$app/stores';
+ import { back } from '$lib/utils';
+ import { pin } from '$lib/store';
+
+ export let data;
+ export let form;
+
+ let { rates } = data;
+ let { amount, id } = $page.params;
+ let { currency } = data.user;
+ let loading;
+
+ let submit = () => (loading = true);
+ $: update(form);
+ let update = () => {
+ if (form?.message.includes('pin')) $pin = undefined;
+ loading = false;
+ };
+
+ $: rate = rates[currency];
+</script>
+
+<button class="ml-5 md:ml-20 mt-5 md:mt-10 hover:opacity-80" on:click={back}>
+ <Icon icon="arrow-left" style="w-10" />
+</button>
+
+{#if form?.message}
+ <div class="text-red-600 text-center">
+ {form.message}
+ </div>
+{/if}
+
+<div class="container px-4 mt-20 max-w-xl mx-auto">
+ <Numpad bind:amount bind:currency bind:rate {submit} />
+
+ <form method="POST" use:enhance on:submit={submit}>
+ <input name="id" value={id} type="hidden" />
+ <input name="amount" value={amount} type="hidden" />
+ <input name="pin" value={$pin} type="hidden" />
+
+ <div class="flex w-full">
+ <button
+ type="submit"
+ class="opacity-100 hover:opacity-80'} rounded-2xl border py-3 font-bold mx-auto mt-2 bg-black text-white px-4 w-24"
+ >
+ {#if loading}
+ <Spinner />
+ {:else}
+ {$t('payments.send')}
+ {/if}
+ </button>
+ </div>
+ </form>
+</div>
diff --git a/src/routes/(app)/fund/[id]/withdraw/+server.js b/src/routes/(app)/fund/[id]/withdraw/+server.js
new file mode 100644
index 00000000..0f9a23f3
--- /dev/null
+++ b/src/routes/(app)/fund/[id]/withdraw/+server.js
@@ -0,0 +1,6 @@
+import { json } from '@sveltejs/kit';
+import { auth, post } from '$lib/utils';
+
+export async function POST({ cookies, request }) {
+ return json(await post('/take', await request.json(), auth(cookies)));
+}